//
//  SensorStatusViewController.m
//  GravityControl
//
//  Created by Javier Quevedo on 10/06/2009.
//  Copyright VRIJE 2009. All rights reserved.
//

#import "SensorStatusViewController.h"
#import "GravityAgent.h"



@implementation SensorStatusViewController
@synthesize xAccelLabel, yAccelLabel, zAccelLabel, xSpeedLabel, ySpeedLabel, zSpeedLabel, gravityAgent, angle;

#pragma mark Socket communication


// The designated initializer. Override to perform setup that is required before the view is loaded.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {

	}
	
    return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	[xAccelLabel setText:@"Accel X"];
	gravityAgent = [GravityAgent sharedAgent];

	
	[[NSNotificationCenter defaultCenter] addObserver:self 
										selector:@selector(trackNotificationGestures:) 
										name:nGravityUpdated object:gravityAgent];

	
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

#pragma mark Button Controllers
- (IBAction) sliceTouched:(id) sender{
	NSLog(@"Slice touched");	
}

- (IBAction) duckTouched:(id) sender{
	NSLog(@"Duck touched");	
}

#pragma mark Notification trackers
-(void) trackNotificationGestures: (NSNotification *)notificacion{
	
	//NSString *msgString = [NSString stringWithFormat:@"ACX %f ACY %f ACZ %f",gravityAgent.accel.x, gravityAgent.accel.y, gravityAgent.accel.z];
	
	/*char * aPointer = (char *) [msgString cStringUsingEncoding:NSASCIIStringEncoding];
	char angleCString[strlen(aPointer)];
	strncpy(angleCString, aPointer, strlen(aPointer));

	if (sock)
		write(sock, angleCString, sizeof(angleCString));*/
	
	[xSpeedLabel setText:[NSString stringWithFormat:@"%f", gravityAgent.velocity.x]];
	[ySpeedLabel setText:[NSString stringWithFormat:@"%f", gravityAgent.velocity.y]];
	[zSpeedLabel setText:[NSString stringWithFormat:@"%f", gravityAgent.velocity.z]];
	[xAccelLabel setText:[NSString stringWithFormat:@"%f", gravityAgent.accel.x]];
	[yAccelLabel setText:[NSString stringWithFormat:@"%f", -gravityAgent.accel.y]];
	[zAccelLabel setText:[NSString stringWithFormat:@"%f", gravityAgent.accel.z]];
	[angle setText:[NSString stringWithFormat:@"%@", gravityAgent.angle]];
	
}



- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end
